/***************************************************************************************************
  *Copyright(C),2010-2016,Sumscope
  *FileName	:  time.h
  *Author	:  scofined.qi
  *Version	:  1.0
  *Date		:  2015/12/18
  *Desc		:  //用于主要说明此程序文件完成的主要功能
  *Relation :  
  *Others	:  //其他内容说明
  *Function :  //主要函数列表，每条记录应包含函数名及功能简要说明
  *History	:  //修改历史记录列表，每条修改记录应包含修改日期、修改者及修改内容简介
***************************************************************************************************/
#pragma once

#include "../strings/BaseString.h"
#include "../core.h"
namespace qb{
namespace base{
    typedef struct _SYSTEMTIME {
        unsigned short wYear;
        unsigned short wMonth;
        unsigned short wDayOfWeek;
        unsigned short wDay;
        unsigned short wHour;
        unsigned short wMinute;
        unsigned short wSecond;
        unsigned short wMilliseconds;
    } SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;

    S_CORE_EXPORT uint64_t GetHighResTimeD();
    S_CORE_EXPORT unsigned int GetHighResTime();

    class S_CORE_EXPORT HighResTime{
		uint64_t		m_time;
	public:
		HighResTime(uint64_t time):m_time(time){}
		HighResTime();
		HighResTime(const HighResTime& rhs):m_time(rhs.m_time){}
		inline uint64_t second()const{ return (unsigned long long)(m_time / 1000000); }
		inline uint32_t minisec()const{ return (unsigned int)(m_time / 1000); }
		inline uint32_t microsec()const{ return (unsigned int)m_time; }
		inline operator uint64_t()const{return m_time;}

		void ToLocalTime(SYSTEMTIME& stLocal)const;
		HighResTime today();
		HighResTime todaypassed();
		BaseString ToString(const char* fmt=0)const;
		inline HighResTime elapsed()const{return HighResTime(GetHighResTimeD()-m_time);}
		inline HighResTime operator-(const HighResTime& rhs){return HighResTime (m_time-rhs.m_time);}
		HighResTime& operator=(const HighResTime& rhs) { m_time = rhs.m_time; return *this; }
		HighResTime& operator-=(const HighResTime& rhs){m_time -= rhs.m_time;return *this;}
		HighResTime& operator+=(const HighResTime& rhs){m_time += rhs.m_time;return *this;}
	};
}//namespace base;
}//namespace qb;

#ifndef _MSC_VER
unsigned long GetTickCount();
#endif